
************************************
************ MI Framework **********
************************************
use "...\new_electorate_imputed_data.dta", clear


mi import wide, imputed(score_kand=kand_sub_1 kand_sub_2 kand_sub_3 kand_sub_4 kand_sub_5 score_issue=issue_sub_1 issue_sub_2 issue_sub_3 issue_sub_4 issue_sub_5 /// 
score_pid=pid_sub_1 pid_sub_2 pid_sub_3 pid_sub_4 pid_sub_5 score_ptv=ptv_sub_1 ptv_sub_2 ptv_sub_3 ptv_sub_4 ptv_sub_5 ) clear
*mi extract 0, clear



mi describe
mi varying

set more off


**Robustness 1**

 
egen miss_kand=sum(flag_kand), by(lfd)
gen miss=miss_kand+flag_pid+flag_issue

tab miss_kand if group == 1 & stack == 1


estpost correlate miss flag_pid flag_issue miss_kand wissen polint if stack == 1 & group == 1 [aw=w_gesamt], matrix casewise
est store correlation_miss

esttab correlation_miss using correlationmiss.csv, replace b(2) not nose noobs nonum unstack compress nogaps scsv label


************************************
*********** MI Calculations*********
************************************

*************************************************************
*************************************************************
******* Michigan Model w/o immigrant spec. factors **********
*************************************************************
*************************************************************
************************************

* H1
* Michigan model for immigrant voters
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung c.polint  i.gruppe  i.stack [pw=w_gesamt] if group==1 || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung c.polint  i.gruppe  i.stack [pw=w_gesamt] if group==1 || case:
est store h1_migrants
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* Michigan model for native voters
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung c.polint i.gruppe i.stack [pw=w_gesamt] if group==0 || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung c.polint i.gruppe i.stack [pw=w_gesamt] if group==0 || case:
est store h1_natives
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* H2
* Difference between natives and immigrants
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue##c.group c.score_kand##c.group c.score_pid##c.group alter maennlich bildung c.polint i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue##c.group c.score_kand##c.group c.score_pid##c.group alter maennlich bildung c.polint i.gruppe i.stack [pw=w_gesamt] || case:
est store h2
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* Difference between natives and immigrants for all cases w/ valid candidate evaluations
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue##c.group c.score_kand##c.group c.score_pid##c.group alter maennlich bildung c.polint i.gruppe i.stack if flag_kand==0 [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5
mi estimate, post: mixed score_ptv c.score_issue##c.group c.score_kand##c.group c.score_pid##c.group alter maennlich bildung c.polint i.gruppe i.stack if flag_kand==0 [pw=w_gesamt] || case:
est store h2_0
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

esttab   h1_natives h1_migrants h2 h2_0 using modelle_h12.rtf, replace b(2) se(2) order(score_pid) stats(N r2 aic2 bic2 icc2, fmt(0 2 0 0 2)) star(* 0.05 ** 0.01  *** 0.001) nonum nolegend nonotes label nogaps

* H1
* Separate analyses for each migrant group
* Turkish descent
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung c.polint i.gruppe  i.stack [pw=w_gesamt] if gruppe==1 || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung c.polint i.gruppe  i.stack [pw=w_gesamt] if gruppe==1 || case:
est store h1_migrantst
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* Post-soviet descent
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung c.polint i.gruppe  i.stack [pw=w_gesamt] if gruppe==2 || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung  c.polint i.gruppe  i.stack [pw=w_gesamt] if gruppe==2 || case:
est store h1_migrantsr
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


** Comparison between natives and immigrant groups
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue##i.gruppe c.score_kand##i.gruppe c.score_pid##i.gruppe alter maennlich bildung c.polint i.gruppe  i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue##i.gruppe c.score_kand##i.gruppe c.score_pid##i.gruppe alter maennlich bildung c.polint i.gruppe  i.stack [pw=w_gesamt] || case:
est store h12b
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue##i.gruppe c.score_kand##i.gruppe c.score_pid##i.gruppe alter maennlich bildung c.polint i.gruppe  i.stack [pw=w_gesamt] if flag_kand==0 || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue##i.gruppe c.score_kand##i.gruppe c.score_pid##i.gruppe alter maennlich bildung c.polint i.gruppe  i.stack [pw=w_gesamt] || case:
est store h12b_0
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

esttab h1_migrantst h1_migrantsr h12b h12b_0 using modelle_h12b.rtf, replace b(2) se(2) order(score_pid) stats(N r2 aic2 bic2 icc2, fmt(0 2 0 0 2)) star(* 0.05 ** 0.01  *** 0.001) nonum nolegend nonotes label nogaps


* Coefficient plots
set scheme plottig

* Mig vs Natives, Figure 1
coefplot (h1_natives, msymbol(O)) (h1_migrants, msymbol(D)), headings(score_pid="  {bf:Michigan model}" ///
 alter="{bf:Controls}") ///
order(score_pid score_kand score_issue alter maennlich bildung polint gruppe generation2 ) drop (*.generation2 || *.gruppe || *.stack || _cons)  xline(0, lpatter(solid)) plotlabels("Natives" "Migrants" ) ///
 coeflabels( sozoek="Tax/spend proximity 0-10" libaut="Lib/auth proximity 0-10" ///
score_pid="Party identification" diskriminierung="Discrimination experience" gruppe="DRUS (base DTÜR)"  3.generation2="1st gen (base natives)" ///
2.generation2="1.5 gen (base natives)"  1.generation2="2nd gen (base natives)" 1.identifikation="IDF=more German than foreign" 2.identifikation="IDF=German and foreign" ///
score_kand="Candidate evaluation" polint="Political Interest" score_issue="Issue Competency" maennlich="Male" alter="Age" bildung="Educational level" stack="Party") xlabel(-4(1)5.5, grid)  xscale(range(-1 4)) name(imges, replace)

* Turkish vs Post-Soviet vs Natives, Figure 4 Appendix
coefplot (h1_natives, msymbol(O)) (h1_migrantst, msymbol(D)) (h1_migrantsr, msymbol(T)), headings(score_pid="  {bf:Michigan model}" ///
 alter="{bf:Controls}") ///
order(score_pid score_kand score_issue alter maennlich bildung polint gruppe generation2 ) drop (*.generation2 || *.gruppe || *.stack || _cons)  xline(0, lpatter(solid)) ///
plotlabels("Natives" "Turkish immigrants" "Post-Soviet immigrants") ///
 coeflabels( sozoek="Tax/spend proximity 0-10" libaut="Lib/auth proximity 0-10" ///
score_pid="Party identification" diskriminierung="Discrimination experience" gruppe="DRUS (base DTÜR)"  3.generation2="1st gen (base natives)" ///
2.generation2="1.5 gen (base natives)"  1.generation2="2nd gen (base natives)" 1.identifikation="IDF=more German than foreign" 2.identifikation="IDF=German and foreign" ///
score_kand="Candidate evaluation" polint="Political Interest" score_issue="Issue Competency" maennlich="Male" alter="Age" bildung="Educational level" stack="Party") xlabel(-4(1)5.5, grid)  xscale(range(-1 4)) name(imges, replace)






*************************************************************
*************************************************************
******* Direct effect of immigrant specific factors *********
*************************************************************
*************************************************************


* H3
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint i.gruppe  i.stack [pw=w_gesamt] || case:
mi test mean_diskr share hi_idf
est store h4
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* H3 baseline model
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv cc.mean_diskr share c.hi_idf alter maennlich bildung c.polint i.gruppe  i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv cc.mean_diskr share c.hi_idf alter maennlich bildung c.polint i.gruppe  i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case:
est store h40
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* H3 baseline model ohne controls
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv cc.mean_diskr share c.hi_idf i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv cc.mean_diskr share c.hi_idf i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case:
est store h40c
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* H4 interaction effect between discrimination and ethnic identity

scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid c.mean_diskr c.share c.mean_diskr##c.hi_idf  alter maennlich bildung c.polint i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr##c.hi_idf    alter maennlich bildung c.polint i.gruppe  i.stack [pw=w_gesamt] || case:
est store h41
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace
mi test mean_diskr share hi_idf


esttab h4 h40 h41 using modelle_h4.rtf, replace b(2) se(2) stats(N r2 aic2 bic2, fmt(0 2 0 0 2)) star(* 0.05 ** 0.01  *** 0.001) nonum nolegend nonotes label nogaps

esttab h1_natives h1_migrants h4 h40 h40c using tabelle5.rtf, replace b(2) se(2) stats(N r2 aic2 bic2 , fmt(0 2 0 0)) star(* 0.05 ** 0.01  *** 0.001) nonum nolegend nonotes label nogaps


* Separate analyses for each migrant group
* Turkish descent
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint i.gruppe  i.stack  if gruppe==1 [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint i.gruppe  i.stack  if gruppe==1 [pw=w_gesamt] || case:
est store h4t
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.share c.mean_diskr  c.hi_idf   i.stack  if gruppe==1&bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.share c.mean_diskr  c.hi_idf   i.stack  if gruppe==1&bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case:
est store h40t
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr##c.hi_idf    alter maennlich bildung c.polint i.gruppe  i.stack   if gruppe==1 [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr##c.hi_idf    alter maennlich bildung c.polint i.gruppe  i.stack   if gruppe==1 [pw=w_gesamt] || case:
est store h41t
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv cc.mean_diskr share c.hi_idf i.stack if bildung!=. & alter!=. & polint!=.& gruppe==1 [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv cc.mean_diskr share c.hi_idf i.stack if bildung!=. & alter!=. & polint!=. & gruppe==1 [pw=w_gesamt] || case:
est store h40ct
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace



* Post-soviet descent
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint i.gruppe  i.stack  if gruppe==2 [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint i.gruppe  i.stack  if gruppe==2 [pw=w_gesamt] || case:
est store h4r
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.share c.mean_diskr  c.hi_idf   i.stack  if gruppe==2&bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.share c.mean_diskr  c.hi_idf   i.stack  if gruppe==2&bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case:
est store h40r
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr##c.hi_idf    alter maennlich bildung c.polint i.gruppe  i.stack   if gruppe==2 [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr##c.hi_idf    alter maennlich bildung c.polint i.gruppe  i.stack   if gruppe==2 [pw=w_gesamt] || case:
est store h41r
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv cc.mean_diskr share c.hi_idf i.stack if bildung!=. & alter!=. & polint!=.& gruppe==2 [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv cc.mean_diskr share c.hi_idf i.stack if bildung!=. & alter!=. & polint!=. & gruppe==2 [pw=w_gesamt] || case:
est store h40cr
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


esttab  h4t h4r h40t h40r h41t h41r using modelle_h4b.rtf, replace b(2) se(2) stats(N r2 aic2 bic2, fmt(0 2 0 0)) star(* 0.05 ** 0.01  *** 0.001) nonum nolegend nonotes label nogaps

esttab h1_migrantst h1_migrantsr  h4t h4r h40t h40r h40ct h40cr using tabelle5tr.rtf, replace b(2) se(2) stats(N r2 aic2 bic2 , fmt(0 2 0 0)) star(* 0.05 ** 0.01  *** 0.001) nonum nolegend nonotes label nogaps




*************************************************************
*************************************************************
******* Moderating effect of immigrant specific factors *****
*************************************************************
*************************************************************
**reacting to reviewer 3
* H5
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed c.score_ptv c.score_pid##c.share c.score_kand##c.share c.score_issue##c.share alter bildung maennlich c.polint i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##c.share c.score_kand##c.share c.score_issue##c.share alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_1
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: mixed c.score_ptv c.score_pid##c.hi_idf c.score_kand##c.hi_idf  c.score_issue##c.hi_idf  alter bildung maennlich c.polint i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##c.hi_idf c.score_kand##c.hi_idf  c.score_issue##c.hi_idf  alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_2
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: mixed c.score_ptv c.score_pid##c.mean_diskr c.score_kand##c.mean_diskr  c.score_issue##c.mean_diskr  alter bildung maennlich c.polint i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##c.mean_diskr c.score_kand##c.mean_diskr  c.score_issue##c.mean_diskr  alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_3
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr  c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr alter bildung maennlich c.polint i.stack i.gruppe [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post:  mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr alter bildung maennlich c.polint i.stack i.gruppe [pw=w_gesamt] || case:
est store h5_4
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


*estimating interactions one by one
log using "interactions.smcl", replace
scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid##c.share c.score_kand  c.score_issue c.share c.hi_idf c.mean_diskr  alter bildung maennlich c.polint i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##c.share c.score_kand  c.score_issue c.share c.hi_idf c.mean_diskr   alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_41
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace



scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid##c.hi_idf c.share c.score_kand  c.score_issue c.share  c.mean_diskr  alter bildung maennlich c.polint i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##c.hi_idf c.share c.score_kand  c.score_issue c.share  c.mean_diskr   alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_42
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace



scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid##c.mean_diskr  c.share c.score_kand  c.score_issue c.share c.hi_idf  alter bildung maennlich c.polint i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##c.mean_diskr  c.share c.score_kand  c.score_issue c.share c.hi_idf   alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_43
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid c.score_kand##c.share  c.score_issue c.share c.hi_idf c.mean_diskr  alter bildung maennlich c.polint i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid c.score_kand##c.share  c.score_issue c.share c.hi_idf c.mean_diskr   alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_44
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace



scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid c.score_kand##c.hi_idf c.share  c.score_issue c.share  c.mean_diskr  alter bildung maennlich c.polint i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid c.score_kand##c.hi_idf c.share  c.score_issue c.share c.mean_diskr   alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_45
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace



scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid c.score_kand##c.mean_diskr    c.score_issue c.share c.hi_idf   alter bildung maennlich c.polint i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid c.score_kand##c.mean_diskr    c.score_issue c.share c.hi_idf   alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_46
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid c.score_kand c.mean_diskr  c.share##c.score_issue  c.hi_idf   alter bildung maennlich c.polint i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid c.score_kand c.mean_diskr  c.share##c.score_issue  c.hi_idf   alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_47
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace



scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid c.score_kand c.mean_diskr  c.share  c.score_issue##c.hi_idf    alter bildung maennlich c.polint i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid c.score_kand c.mean_diskr  c.share  c.score_issue##c.hi_idf      alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_48
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace



scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid c.score_kand c.share  c.score_issue##c.mean_diskr  c.share c.hi_idf   alter bildung maennlich c.polint i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid c.score_kand c.share  c.score_issue##c.mean_diskr  c.share c.hi_idf   alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_49
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

log close


*** Checks for R3 - non linearity **

egen length_ord = cut(share), group(3) 
egen ethid_ord = cut(hi_idf), group(3) 
* so linkssteil, kann man kaum sinnvollteilen
recode mean_diskr 0=0 1/1.9=1 1.91/3=2, gen(diskr_ord)

log using "new_electorate_R3", replace


scalar aic=0
scalar bic=0
mi xeq 1/5: mixed c.score_ptv c.score_pid##i.b1.length_ord c.score_pid c.score_pid c.score_kand##i.b1.length_ord c.score_kand c.score_kand c.score_issue##i.b1.length_ord c.score_issue c.score_issue alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##i.b1.length_ord c.score_pid c.score_pid c.score_kand##i.b1.length_ord c.score_kand c.score_kand c.score_issue##i.b1.length_ord c.score_issue c.score_issue alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_5org
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: mixed c.score_ptv c.score_pid##i.b1.ethid_ord c.score_pid c.score_pid c.score_kand##i.b1.ethid_ord c.score_kand c.score_kand c.score_issue##i.b1.ethid_ord c.score_issue c.score_issue alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##i.b1.ethid_ord c.score_pid c.score_pid c.score_kand##i.b1.ethid_ord c.score_kand c.score_kand c.score_issue##i.b1.ethid_ord c.score_issue c.score_issue alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_5org
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace




scalar aic=0
scalar bic=0
mi xeq 1/5: mixed c.score_ptv c.score_pid##i.b1.diskr_ord c.score_pid c.score_pid c.score_kand##i.b1.diskr_ord c.score_kand c.score_kand c.score_issue##i.b1.diskr_ord c.score_issue c.score_issue alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##i.b1.diskr_ord c.score_pid c.score_pid c.score_kand##i.b1.diskr_ord c.score_kand c.score_kand c.score_issue##i.b1.diskr_ord c.score_issue c.score_issue alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_5org
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace
*margins, at(share=(0.1(.1)1)) dydx(score_kand)



scalar aic=0
scalar bic=0
mi xeq 1/5: mixed c.score_ptv c.score_pid##i.b1.length_ord c.score_pid##i.b1.ethid_ord c.score_pid##i.b1.diskr_ord  c.score_kand##i.b1.length_ord  c.score_kand##i.b1.ethid_ord c.score_kand##i.b1.diskr_ord  c.score_issue##i.b1.length_ord  c.score_issue##i.b1.ethid_ord c.score_issue##i.b1.diskr_ord  alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##i.b1.length_ord c.score_pid##i.b1.ethid_ord c.score_pid##i.b1.diskr_ord  c.score_kand##i.b1.length_ord  c.score_kand##i.b1.ethid_ord c.score_kand##i.b1.diskr_ord  c.score_issue##i.b1.length_ord  c.score_issue##i.b1.ethid_ord c.score_issue##i.b1.diskr_ord  alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_5alle
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

log close

*esttab h5_1 h5_2 h5_3 h5_4 using modelle_h5.rtf, replace b(2) se(2) stats(N r2 aic2 bic2 , fmt(0 2 0 0)) star(* 0.05 ** 0.01  *** 0.001) nonum nolegend nonotes label nogaps



** Test interaction effect at different levels of share
* mean 0.66, max=1
gen meanshare=share-0.6667
gen maxshare=share-1
mi estimate, post: mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr score_kand score_issue alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:

mi estimate, post: mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr score_kand score_issue alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est sto share1
mi estimate, post: mixed c.score_ptv c.score_pid##c.meanshare c.score_pid##c.hi_idf c.score_pid##c.mean_diskr score_kand score_issue alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est sto share2
mi estimate, post: mixed c.score_ptv c.score_pid##c.maxshare c.score_pid##c.hi_idf c.score_pid##c.mean_diskr score_kand score_issue alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est sto share3



* separate analyses for each migrant group
* Turkish descent
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr  c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr alter bildung maennlich c.polint i.stack if gruppe==1 [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post:  mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr alter bildung maennlich c.polint i.stack if gruppe==1 [pw=w_gesamt] || case:
est store h5_4t
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* Post-soviet descent
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr  c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr alter bildung maennlich c.polint i.stack if gruppe==2 [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post:  mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr alter bildung maennlich c.polint i.stack if gruppe==2 [pw=w_gesamt] || case:
est store h5_4r
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

esttab h5_4t h5_4r using modelle_h5b.rtf, replace b(2) se(2) stats(N r2 aic bic icc2, fmt(0 2 0 0 2)) star(* 0.05 ** 0.01  *** 0.001) nonum nolegend nonotes label nogaps


/*
egen cat_share = cut(share_t) if gruppe==2, group(4) label
mean pid if gruppe==2&flag_pid==0&stack==1, over(cat_share)

*/

************************************
* H6
tab generation2, gen(gen)

*with time spent in Germany
mi estimate, post cmdok: sem (alter bildung maennlich polint flag_pid -> score_pid ) (stack  score_pid  score_kand score_issue gruppe  flag_ptv-> score_ptv, ) ///
(score_pid flag_kand -> score_kand, ) (score_pid flag_issue-> score_issue, )(share -> flag_pid) (share->flag_kand)(share->flag_issue) (share->flag_ptv) [pweight = w_gesamt], cov( e.score_kand*e.score_issue) nocapslatent
*mi xeq: estat teffects
*mi est,cmdok: estat gof, stats(all)
est store sem1

*with ethnic id
mi estimate, post cmdok: sem (alter bildung maennlich polint flag_pid -> score_pid ) (stack  score_pid  score_kand score_issue gruppe  flag_ptv-> score_ptv, ) ///
(score_pid flag_kand -> score_kand, ) (score_pid flag_issue-> score_issue, )(hi_idf -> flag_pid) (hi_idf->flag_kand)(hi_idf->flag_issue) (hi_idf->flag_ptv) [pweight = w_gesamt], cov( e.score_kand*e.score_issue) nocapslatent
*mi xeq: estat teffects
*mi est,cmdok: estat gof, stats(all)
est store sem2

*with discrimination
mi estimate, post cmdok: sem (alter bildung maennlich polint flag_pid -> score_pid ) (stack  score_pid  score_kand score_issue gruppe  flag_ptv-> score_ptv, ) ///
(score_pid flag_kand -> score_kand, ) (score_pid flag_issue-> score_issue, )(mean_dis -> flag_pid) (mean_dis->flag_kand)(mean_dis->flag_issue) (mean_dis->flag_ptv) [pweight = w_gesamt], cov( e.score_kand*e.score_issue) nocapslatent
*mi xeq: estat teffects
*mi est,cmdok: estat gof, stats(all)
est store sem3

*with all three migrant-specific variables
mi estimate, post cmdok: sem (alter bildung maennlich polint flag_pid -> score_pid ) (stack  score_pid  score_kand score_issue gruppe  flag_ptv-> score_ptv, ) ///
(score_pid flag_kand -> score_kand, ) (score_pid flag_issue-> score_issue, )(share hi_idf mean_dis -> flag_pid) (share hi_idf mean_dis->flag_kand)(share hi_idf mean_dis->flag_issue) (share hi_idf mean_dis->flag_ptv) [pweight = w_gesamt], cov( e.score_kand*e.score_issue) nocapslatent
*mi xeq: estat teffects
*mi est,cmdok: estat gof, stats(all)
est store sem4



esttab sem1 sem2 sem3 sem4 using modelle_h6.rtf, replace b(2) se(2) stats(N r2 aic bic icc2, fmt(0 2 0 0 2)) star(* 0.05 ** 0.01  *** 0.001) nonum nolegend nonotes label nogaps



mi estimate, post cmdok: sem (alter bildung maennlich polint flag_pid -> score_pid ) (stack  score_pid  score_kand score_issue   flag_ptv-> score_ptv, ) ///
(score_pid flag_kand -> score_kand, ) (score_pid flag_issue-> score_issue, )(share hi_idf mean_dis -> flag_pid) (share hi_idf mean_dis->flag_kand)(share hi_idf mean_dis->flag_issue) (share hi_idf mean_dis->flag_ptv) if gruppe == 1 [pweight = w_gesamt], cov( e.score_kand*e.score_issue) nocapslatent
*mi xeq: estat teffects
*mi est,cmdok: estat gof, stats(all)
est store sem4t

mi estimate, post cmdok: sem (alter bildung maennlich polint flag_pid -> score_pid ) (stack  score_pid  score_kand score_issue   flag_ptv-> score_ptv, ) ///
(score_pid flag_kand -> score_kand, ) (score_pid flag_issue-> score_issue, )(share hi_idf mean_dis -> flag_pid) (share hi_idf mean_dis->flag_kand)(share hi_idf mean_dis->flag_issue) (share hi_idf mean_dis->flag_ptv) if gruppe == 2 [pweight = w_gesamt], cov( e.score_kand*e.score_issue) nocapslatent
*mi xeq: estat teffects
*mi est,cmdok: estat gof, stats(all)
est store sem4r


esttab sem1 sem2 sem3 sem4 sem4t sem4r using modelle_h6b.rtf, replace b(2) se(2) stats(N r2 aic bic icc2, fmt(0 2 0 0 2)) star(* 0.05 ** 0.01  *** 0.001) nonum nolegend nonotes label nogaps



**** Robustness-Checks ****
* without imputated cases

mixed score_ptv c.score_issue##c.group c.score_kand##c.group c.score_pid##c.group alter maennlich bildung c.polint i.gruppe i.stack [pw=w_gesamt] || case:

mixed score_ptv c.score_issue c.score_kand c.score_pid c.mean_diskr share c.hi_idf alter maennlich bildung c.polint i.gruppe  i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case:

mixed score_ptv c.mean_diskr share c.hi_idf i.stack if bildung!=. & alter!=. & polint!=. & gruppe==2 [pw=w_gesamt] || case:

mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store imp1

*full model
mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint i.gruppe  i.stack [pw=w_gesamt] || case:
est store imp_full

sem (alter bildung maennlich polint flag_pid -> score_pid ) (stack  score_pid  score_kand score_issue gruppe  flag_ptv-> score_ptv, ) ///
(score_pid flag_kand -> score_kand, ) (score_pid flag_issue-> score_issue, )(share hi_idf mean_dis -> flag_pid) (share hi_idf mean_dis->flag_kand)(share hi_idf mean_dis->flag_issue) (share hi_idf mean_dis->flag_ptv) [pweight = w_gesamt], cov( e.score_kand*e.score_issue) nocapslatent
est store sem_imp


* without non-voters
preserve
drop if wahltn==0

mi estimate: mixed score_ptv c.score_issue##c.group c.score_kand##c.group c.score_pid##c.group alter maennlich bildung c.polint i.gruppe i.stack [pw=w_gesamt] || case:
est store v1
mi estimate: mixed score_ptv c.score_issue c.score_kand c.score_pid  c.mean_diskr share c.hi_idf alter maennlich bildung c.polint i.gruppe  i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case:
est store v2
mi estimate: mixed score_ptv c.mean_diskr share c.hi_idf i.stack if bildung!=. & alter!=. & polint!=. & gruppe==2 [pw=w_gesamt] || case:
est store v3
mi estimate: mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store v4
*full model
mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint i.gruppe  i.stack [pw=w_gesamt] || case:
est store v_full

mi estimate, cmdok: sem (alter bildung maennlich polint flag_pid -> score_pid ) (stack  score_pid  score_kand score_issue gruppe  flag_ptv-> score_ptv, ) ///
(score_pid flag_kand -> score_kand, ) (score_pid flag_issue-> score_issue, )(share hi_idf mean_dis -> flag_pid) (share hi_idf mean_dis->flag_kand)(share hi_idf mean_dis->flag_issue) (share hi_idf mean_dis->flag_ptv) [pweight = w_gesamt], cov( e.score_kand*e.score_issue) nocapslatent
est store vsem
restore


* only non-voters
preserve
drop if wahltn==1

mi estimate: mixed score_ptv c.score_issue##c.group c.score_kand##c.group c.score_pid##c.group alter maennlich bildung c.polint i.gruppe i.stack [pw=w_gesamt] || case:

mi estimate: mixed score_ptv c.score_issue c.score_kand c.score_pid c.mean_diskr share c.hi_idf alter maennlich bildung c.polint i.gruppe  i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case:

mi estimate: mixed score_ptv c.mean_diskr share c.hi_idf i.stack if bildung!=. & alter!=. & polint!=. & gruppe==2 [pw=w_gesamt] || case:

mi estimate: mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store nv4

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint i.gruppe  i.stack [pw=w_gesamt] || case:
est store nv_full

mi estimate, cmdok: sem (alter bildung maennlich polint flag_pid -> score_pid ) (stack  score_pid  score_kand score_issue gruppe  flag_ptv-> score_ptv, ) ///
(score_pid flag_kand -> score_kand, ) (score_pid flag_issue-> score_issue, )(share hi_idf mean_dis -> flag_pid) (share hi_idf mean_dis->flag_kand)(share hi_idf mean_dis->flag_issue) (share hi_idf mean_dis->flag_ptv) [pweight = w_gesamt], cov( e.score_kand*e.score_issue) nocapslatent
est store nvsem

restore


* mit Generation statt length of stay genn2 und genn3 sind die 2. und 1.5. generation, base category 1st

tab generation2, gen(genn)

mi estimate: mixed score_ptv c.score_issue##c.group c.score_kand##c.group c.score_pid##c.group alter maennlich bildung c.polint i.gruppe i.stack [pw=w_gesamt] || case:

mi estimate: mixed score_ptv c.mean_diskr share genn1 genn1 genn2 genn3  c.hi_idf alter maennlich bildung c.polint i.gruppe  i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case:

mi estimate: mixed score_ptv c.mean_diskr share genn1 genn1 genn2 genn3  c.hi_idf i.stack if bildung!=. & alter!=. & polint!=. & gruppe==2 [pw=w_gesamt] || case:

mi estimate: mixed c.score_ptv c.score_pid##i.b3.generation2 c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##i.b3.generation2 c.score_kand##c.hi_idf c.score_kand##c.mean_diskr c.score_issue##i.b3.generation2 c.score_issue##c.hi_idf c.score_issue##c.mean_diskr i.generation2 alter bildung maennlich c.polint i.gruppe i.stack  [pw=w_gesamt] || case:
est store gen

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid genn1 genn1 genn2 genn3 c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint i.gruppe  i.stack [pw=w_gesamt] || case:
est store gen_full

mi estimate, cmdok: sem (alter bildung maennlich polint flag_pid -> score_pid ) (stack  score_pid  score_kand score_issue gruppe  flag_ptv-> score_ptv, ) ///
(score_pid flag_kand -> score_kand, ) (score_pid flag_issue-> score_issue, )(genn1 genn1 genn2 genn3 hi_idf mean_dis -> flag_pid) (genn1 genn1 genn2 genn3 hi_idf mean_dis->flag_kand)(genn1 genn1 genn2 genn3  hi_idf mean_dis->flag_issue) (genn1 genn1 genn2 genn3  hi_idf mean_dis->flag_ptv) [pweight = w_gesamt], cov( e.score_kand*e.score_issue) nocapslatent
est store gen_sem

** by party **

forvalues val=1/6{
mi estimate, post: regr score_ptv c.score_issue c.score_kand c.score_pid c.mean_diskr share c.hi_idf alter maennlich bildung c.polint i.gruppe if stack==`val' [pw=w_gesamt]
}

forvalues val=1/6{
mi estimate, post: regr score_ptv c.score_issue c.score_kand c.score_pid c.mean_diskr share c.hi_idf alter maennlich bildung c.polint religioe gew i.beruf i.gruppe if stack==`val' [pw=w_gesamt]
}

forvalues val=1/6{
mi estimate: regr c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr i.generation2 alter bildung maennlich c.polint i.gruppe  if stack==`val' [pw=w_gesamt] 
}




forvalues val=1/6{
mi estimate, cmdok: sem (alter bildung maennlich polint flag_pid -> score_pid ) (  score_pid  score_kand score_issue gruppe  flag_ptv-> score_ptv, ) ///
(score_pid flag_kand -> score_kand, ) (score_pid flag_issue-> score_issue, )(share hi_idf mean_dis -> flag_pid) (share hi_idf mean_dis->flag_kand)(share hi_idf mean_dis->flag_issue) (share hi_idf mean_dis->flag_ptv) if stack==`val' [pweight = w_gesamt], cov( e.score_kand*e.score_issue) nocapslatent
}



** Robustnesschecks Round Two **

* with fixed-effects for federal state
* H1
* Michigan model for immigrant voters
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung c.polint i.bula  i.gruppe  i.stack [pw=w_gesamt] if group==1 || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung c.polint i.bula  i.gruppe  i.stack [pw=w_gesamt] if group==1 || case:
est store h1_natives
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace



* H3
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint i.bula  i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint i.bula  i.gruppe  i.stack [pw=w_gesamt] || case:
mi test mean_diskr share hi_idf
est store h4
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* H3 baseline model
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv cc.mean_diskr share c.hi_idf alter maennlich bildung c.polint i.bula  i.gruppe  i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv cc.mean_diskr share c.hi_idf alter maennlich bildung c.polint i.bula  i.gruppe  i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case:
est store h40
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* H3 baseline model ohne controls
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv cc.mean_diskr share c.hi_idf i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv cc.mean_diskr share c.hi_idf i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case:
est store h40c
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* H4 interaction effect between discrimination and ethnic identity
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid c.mean_diskr c.share c.mean_diskr##c.hi_idf  alter maennlich bildung c.polint i.bula  i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr##c.hi_idf    alter maennlich bildung c.polint i.bula  i.gruppe  i.stack [pw=w_gesamt] || case:
est store h41
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace
mi test mean_diskr share hi_idf



** H5 Moderating effect of immigrant specific factors **
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr alter bildung maennlich c.polint i.bula  i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr alter bildung maennlich c.polint i.bula  i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_4
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


*H6 formative effect
*with all three migrant-specific variables
mi estimate, post cmdok: sem (alter bildung maennlich polint flag_pid  -> score_pid ) (stack  score_pid  score_kand score_issue gruppe  flag_ptv-> score_ptv, ) ///
(score_pid flag_kand -> score_kand, ) (score_pid flag_issue-> score_issue, )(share hi_idf mean_dis -> flag_pid) (share hi_idf mean_dis->flag_kand)(share hi_idf mean_dis->flag_issue) (share hi_idf mean_dis->flag_ptv) [pweight = w_gesamt], cov( e.score_kand*e.score_issue) nocapslatent
*mi xeq: estat teffects
*mi est,cmdok: estat gof, stats(all)
est store sem4



* without imputated cases that were imputated for everyone with missings for pid cand issue or ptv thus listwise deletion*
gen missings=flag_kand+flag_issue+flag_pid+flag_ptv

preserve
drop if missings > 0

* H1
* Michigan model for immigrant voters
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung c.polint   i.gruppe  i.stack [pw=w_gesamt] if group==1 || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung c.polint  i.gruppe  i.stack [pw=w_gesamt] if group==1 || case:
est store h1_natives
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace




* H3
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint   i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint   i.gruppe  i.stack [pw=w_gesamt] || case:
mi test mean_diskr share hi_idf
est store h4
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* H3 baseline model
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv cc.mean_diskr share c.hi_idf alter maennlich bildung c.polint  i.gruppe  i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv cc.mean_diskr share c.hi_idf alter maennlich bildung c.polint i.gruppe  i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case:
est store h40
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* H3 baseline model ohne controls
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv cc.mean_diskr share c.hi_idf i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv cc.mean_diskr share c.hi_idf i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case:
est store h40c
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* H4 interaction effect between discrimination and ethnic identity
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid c.mean_diskr c.share c.mean_diskr##c.hi_idf  alter maennlich bildung c.polint   i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr##c.hi_idf    alter maennlich bildung c.polint   i.gruppe  i.stack [pw=w_gesamt] || case:
est store h41
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace
mi test mean_diskr share hi_idf



** H5 Moderating effect of immigrant specific factors **
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr alter bildung maennlich c.polint   i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr alter bildung maennlich c.polint   i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_4
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace





restore



** with income **

* with fixed-effects for federal state
* H1
* Michigan model for immigrant voters
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung c.polint medinc lowinc misinc   i.gruppe  i.stack [pw=w_gesamt] if group==1 || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung c.polint medinc lowinc misinc   i.gruppe  i.stack [pw=w_gesamt] if group==1 || case:
est store h1_migrantsinc
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* Michigan model for native voters
/*scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung c.polint medinc lowinc misinc  i.stack [pw=w_gesamt] if group==0 || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid alter maennlich bildung c.polint medinc lowinc misinc  i.stack [pw=w_gesamt] if group==0 || case:
est store h1_nativesinc
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace
*/

* H3
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint medinc lowinc misinc  i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr  c.hi_idf  alter maennlich bildung c.polint medinc lowinc misinc  i.gruppe  i.stack [pw=w_gesamt] || case:
mi test mean_diskr share hi_idf
est store h4_inc
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* H3 baseline model
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv cc.mean_diskr share c.hi_idf alter maennlich bildung c.polint medinc lowinc misinc   i.gruppe  i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv cc.mean_diskr share c.hi_idf alter maennlich bildung c.polint medinc lowinc misinc   i.gruppe  i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case:
est store h40_inc
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

* H3 baseline model ohne controls
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv cc.mean_diskr share c.hi_idf i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv cc.mean_diskr share c.hi_idf i.stack if bildung!=. & alter!=. & polint!=. [pw=w_gesamt] || case:
est store h40c_inc
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

esttab  h1_migrantsinc h4_inc h40_inc h40c_inc using modelle_inc.rtf, replace b(2) se(2) stats(N r2 aic bic icc2, fmt(0 2 0 0 2)) star(* 0.05 ** 0.01  *** 0.001) nonum nolegend nonotes label nogaps
 
/*
* H4 interaction effect between discrimination and ethnic identity
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed score_ptv c.score_issue c.score_kand c.score_pid c.mean_diskr c.share c.mean_diskr##c.hi_idf  alter maennlich bildung c.polint medinc lowinc misinc   i.gruppe i.stack [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed score_ptv c.score_issue c.score_kand c.score_pid c.share c.mean_diskr##c.hi_idf    alter maennlich bildung c.polint medinc lowinc misinc  i.gruppe  i.stack [pw=w_gesamt] || case:
est store h41
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace
mi test mean_diskr share hi_idf
'/
*/

** H5 Moderating effect of immigrant specific factors **
scalar aic=0
scalar bic=0
mi xeq 1/5: mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##c.share c.score_pid##c.hi_idf c.score_pid##c.mean_diskr c.score_kand##c.share c.score_kand##c.hi_idf c.score_kand##c.mean_diskr c.score_issue##c.share c.score_issue##c.hi_idf c.score_issue##c.mean_diskr alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  [pw=w_gesamt] || case:
est store h5_4_inc
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

** Single interactions
scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid##c.share c.score_kand c.score_issue c.hi_idf c.mean_diskr alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##c.share c.score_kand c.score_issue c.hi_idf c.mean_diskr alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  || case:
est store h5_4_inc1
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid##c.hi_idf  c.share c.score_kand c.score_issue c.hi_idf c.mean_diskr alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##c.hi_idf  c.share c.score_kand c.score_issue c.mean_diskr alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  || case:
est store h5_4_inc2
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid##c.mean_diskr c.share c.score_kand c.score_issue c.hi_idf c.mean_diskr alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid##c.mean_diskr c.share c.score_kand c.score_issue c.hi_idf  alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  || case:
est store h5_4_inc3
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid c.score_kand##c.share c.score_issue c.hi_idf c.mean_diskr alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid c.score_kand##c.share c.score_issue c.hi_idf c.mean_diskr alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  || case:
est store h5_4_inc4
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid c.share c.score_kand##c.hi_idf c.score_issue c.mean_diskr alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid c.share c.score_kand##c.hi_idf c.score_issue  c.mean_diskr alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  || case:
est store h5_4_inc5
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid c.score_kand##c.mean_diskr c.score_issue c.share c.hi_idf  alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid c.score_kand##c.mean_diskr c.score_issue c.share c.hi_idf  alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  || case:
est store h5_4_inc6
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid  c.score_kand c.score_issue##c.share c.hi_idf c.mean_diskr alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid  c.score_kand c.score_issue##c.share c.hi_idf c.mean_diskr alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  || case:
est store h5_4_inc7
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid c.share c.score_kand c.score_issue##c.hi_idf c.mean_diskr alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid c.share c.score_kand c.score_issue##c.hi_idf c.mean_diskr alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  || case:
est store h5_4_inc8
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace


scalar aic=0
scalar bic=0
mi xeq 1/5: quietly mixed c.score_ptv c.score_pid c.share c.score_kand c.score_issue##c.mean_diskr c.hi_idf alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  [pw=w_gesamt] || case: ; estat ic; mat aa=r(S); scalar aic = aic+aa[1,5]; scalar bic = bic+aa[1,6]
scalar aic2= aic/5
scalar bic2= bic/5

mi estimate, post: mixed c.score_ptv c.score_pid c.share c.score_kand c.score_issue##c.mean_diskr c.hi_idf  alter bildung maennlich c.polint medinc lowinc misinc  i.gruppe i.stack  || case:
est store h5_4_inc9
estadd scalar aic2=aic2, replace
estadd scalar bic2=bic2, replace

*H6 formative effect
*with all three migrant-specific variables
mi estimate, post cmdok: sem (alter bildung maennlich polint medinc lowinc misinc flag_pid  -> score_pid ) (stack  score_pid  score_kand score_issue gruppe  flag_ptv-> score_ptv, ) ///
(score_pid flag_kand -> score_kand, ) (score_pid flag_issue-> score_issue, )(share hi_idf mean_dis -> flag_pid) (share hi_idf mean_dis->flag_kand)(share hi_idf mean_dis->flag_issue) (share hi_idf mean_dis->flag_ptv) [pweight = w_gesamt], cov( e.score_kand*e.score_issue) nocapslatent
*mi xeq: estat teffects
*mi est,cmdok: estat gof, stats(all)
est store sem4_inc

esttab sem4_inc using modelle_seminc.rtf, replace b(2) se(2) stats(N r2 aic bic icc2, fmt(0 2 0 0 2)) star(* 0.05 ** 0.01  *** 0.001) nonum nolegend nonotes label nogaps
